function HtmlDatetime() {
    alert("sdas");
    var mydate = new Date()
    var year = mydate.getYear()
    if (year < 1000)
        year += 1900
    var day = mydate.getDay()
    var month = mydate.getMonth()
    var daym = mydate.getDate()
    if (daym < 10)
        daym = "0" + daym
    var dayarray = new Array("Ch&#7911; nh&#7853;t", "Th&#7913; hai", "Th&#7913; ba", "Th&#7913; t&#432;", "Th&#7913; n&#259;m", "Th&#7913; s&aacute;u", "Th&#7913; b&#7843;y")
    var montharray = new Array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12")
    //document.write(" "+dayarray[day]+", ng&agrave;y "+daym+" - "+montharray[month]+" - "+year+"")   
    document.getElementById("htmlDate").innerHTML = "sdasdas"//" " + dayarray[day] + ", ng&agrave;y " + daym + " - " + montharray[month] + " - " + year + ""

}

function Rundate() {
    var q = new Date, c = q.getHours(), s = q.getMinutes(), k = q.getSeconds(), E = q.getDate(), f = q.getDay(), G = q.getMonth() + 1;
    q = q.getFullYear();
    var K = "", Q = "AM";
    if (c >= 12) Q = "PM";
    if (c > 12) c -= 12; if (c == 0) c = 12;
    if (c < 10) c = "0" + c; if (s < 10) s = "0" + s;
    if (k < 10) k = "0" + k;
    switch (f) {
        case 0: K = "Ch\u1ee7 nh\u1eadt, "; break;
        case 1: K = "Th\u1ee9 hai, "; break;
        case 2: K = "Th\u1ee9 3, "; break;
        case 3: K = "Th\u1ee9 4, "; break;
        case 4: K = "Th\u1ee9 5, "; break;
        case 5: K = "Th\u1ee9 6, "; break;
        case 6: K = "Th\u1ee9 7, "
    }
    document.getElementById("htmlDate").innerHTML =
K + E + "/" + G + "/" + q + " - " + c + ":" + s + ":" + k + " " + Q;
    setTimeout("Rundate()", 1E3)
}

function CHHVoting(pollID) {    
    var voted = 0    
    if( $.cookie('Agri_Vote_pollID_' + pollID) != null) {
        alert('Bạn đã bình chọn rồi! Bạn sẽ được bình chọn lại trong vòng 30 phút nữa.');
        return;
    }    
    var str = ''
    $('.noidungbinhchon' + pollID + ' input').each(function() {
        if( $(this).attr('checked') == true) {
            voted = 1;            
        }    
    })
    if( voted == 0)
    {
        alert('Bạn chưa xác nhận thông tin bình chọn !')
        return;
    }
    $('.value_vote' + pollID).each(function() {
        if( $($(this).find('input').get(0)).attr('checked') == true) {
            str += $(this).attr('value_vote') + ","
        }
    })
    var url = '/Modules/Poll/Pages/SetPoll.aspx?strPoll=' + str ;
	$.get(url);
    alert('Thông tin bình chọn đã được gửi !');   
}

function GetHtml(url, div) {
    $(div).html('<center>...Đang tải dữ liệu từ Hệ thống...</center>')
    $.get(encodeURI(url),function(data){
        //get response text only
        var s = data.indexOf('<responseText>')
        var t = data.indexOf('</responseText>')
        var response = data.substring(s + 16, t)        
       
        //$(div).hide('fast')
        $(div).html(response)
       
        //$(div).fadeIn(1000)
    })
}

//Cms_Contetns
function GetCMSContents(url) {
    GetHtml(url, '#uc_CMSContents')
}
function GetListNhac(url) {
    GetHtml(url, '#uc_listnhac')
}
function Get_Page(url) {
    GetHtml(url, '#Getpage')
}
function SearchBDS(city,loaitin,ZoneIDLang,gia,lang,kq)
{
    var txtcity=$('#'+city).val()
    var txtZoneIDLang=$('#'+ZoneIDLang).val()    
    var txtLoaiTin=$('#'+loaitin).val()
    var txtGia=$('#'+gia).val()
    var url='/AjaxCP.aspx?ctrl=/ListBDS&city='+txtcity+'&zoneIDLang='+txtZoneIDLang+'&LoaiTin='+ txtLoaiTin + '&gia='+ txtGia + '&lang='+lang+'&kq='+kq
        GetHtml(url, "#uc_CMS_BDS")
}
function SearchBDS_Home(city,loaitin,ZoneIDLang,gia,lang)
{
    var txtcity=$('#'+city).val()
    var txtZoneIDLang=$('#'+ZoneIDLang).val()    
    var txtLoaiTin=$('#'+loaitin).val()
    var txtGia=$('#'+gia).val()
    var url='/AjaxCP.aspx?ctrl=/KetQuaSearchHome&city='+txtcity+'&zoneIDLang='+txtZoneIDLang+'&LoaiTin='+ txtLoaiTin + '&gia='+ txtGia + '&lang='+lang
        GetHtml(url, "#uc_CMS_BDS_Home")
}
function SearchBDS_HomeVideo(city,loaitin,ZoneIDLang,gia,lang)
{
    var txtcity=$('#'+city).val()
    var txtZoneIDLang=$('#'+ZoneIDLang).val()    
    var txtLoaiTin=$('#'+loaitin).val()
    var txtGia=$('#'+gia).val()
    var url='/AjaxCP.aspx?ctrl=/ResultSearchVideo&city='+txtcity+'&zoneIDLang='+txtZoneIDLang+'&LoaiTin='+ txtLoaiTin + '&gia='+ txtGia + '&lang='+lang
        GetHtml(url, "#uc_CMS_BDS_Home")
}
function HtmlDatetime()
  {
    var mydate=new Date()   
    var year=mydate.getYear()   
    if (year < 1000)   
    year+=1900   
    var day=mydate.getDay()   
    var month=mydate.getMonth()   
    var daym=mydate.getDate()   
    if (daym<10)   
    daym="0"+daym   
    var dayarray=new Array("Ch&#7911; nh&#7853;t","Th&#7913; hai","Th&#7913; ba","Th&#7913; t&#432;","Th&#7913; n&#259;m","Th&#7913; s&aacute;u","Th&#7913; b&#7843;y")   
    var montharray=new Array("01","02","03","04","05","06","07","08","09","10","11","12")   
    //document.write(" "+dayarray[day]+", ng&agrave;y "+daym+" - "+montharray[month]+" - "+year+"")   
    document.getElementById("idDatetime").innerHTML=" "+dayarray[day]+", ng&agrave;y "+daym+" - "+montharray[month]+" - "+year+""
}


function ShowHide(value, idcheck) {
    var list = document.getElementsByName(idcheck);
    for (var i = 0; i < list.length; i++) {
        list[i].style.display = value;
    }
}

function IsNumberInt(str) {
    for (var i = 0; i < str.length; i++) {
        var temp = str.substring(i, i + 1);
        if (!(temp == "," || temp == "." || (temp >= 0 && temp <= 9))) {
            alert("Vui lòng nhập số (0-9)!");
            return str.substring(0, i);
        }
        if (temp == " " || temp == ",")
            return str.substring(0, i);
    }
    return str;
}
function GetNumber(str) {
    for (var i = 0; i < str.length; i++) {
        var temp = str.substring(i, i + 1);
        if (!(temp == "," || temp == "." || (temp >= 0 && temp <= 9))) {
            alert("Dữ liệu nhập vào kiểu số (0-9)!");
            return str.substring(0, i);
        }
        if (temp == " ")
            return str.substring(0, i);
    }
    return str;
}
function FormatNumber(str) {
    var strTemp = GetNumber(str);
    if (strTemp.length <= 3)
        return strTemp;
    strResult = "";
    for (var i = 0; i < strTemp.length; i++)
        strTemp = strTemp.replace(",", "");
    for (var i = strTemp.length; i >= 0; i--) {
        if (strResult.length > 0 && (strTemp.length - i - 1) % 3 == 0)
            strResult = "," + strResult;
        strResult = strTemp.substring(i, i + 1) + strResult;
    }
    return strResult;
}

function SelectCheckBox_All(ctr_This) {
    if (ctr_This) {
        for (var i = 0; i < 1000; i++) {
            var ctr_Check = document.getElementById("CheckAll_" + i);
            if (ctr_Check) {
                ctr_Check.checked = ctr_This.checked;
            }
            else {
                break;
            }
        }
    }

}
function GetAllCheck(str_Alert) {
    if (!hid_ListCheckAll)
        return false;

    hid_ListCheckAll.value = "";
    for (var i = 0; i < 1000; i++) {
        var chk_CheckAll = document.getElementById("CheckAll_" + i);
        if (chk_CheckAll) {
            if (chk_CheckAll.checked) {
                if (hid_ListCheckAll.value.length > 0) {
                    hid_ListCheckAll.value = hid_ListCheckAll.value + "|" + chk_CheckAll.value;
                }
                else {
                    hid_ListCheckAll.value = chk_CheckAll.value;
                }
            }
        }
        else {
            break;
        }
    }

    if (hid_ListCheckAll.value.length < 1) {
        alert(str_Alert);
        return false;
    }
    else {
        return true;
    }
}

function GetCountTimer(year, month, day, h, i, s, iid) {

    dateFuture1 = new Date(year, month, day, h, i, s);
    dateNow = new Date(); //grab current date
    amount = dateFuture1.getTime() - dateNow.getTime(); //calc milliseconds between dates
    delete dateNow;

    // if time is already past
    if (amount < 0) {
        document.getElementById(iid).innerHTML = "<b style='color:red;'>Hết hạn</b>";
    }
    // else date is still good
    else {
        hours = 0; mins = 0; secs = 0; out = "";

        amount = Math.floor(amount / 1000); //kill the "milliseconds" so just secs

        hours = Math.floor(amount / 3600); //hours
        amount = amount % 3600;

        mins = Math.floor(amount / 60); //minutes
        amount = amount % 60;

        secs = Math.floor(amount); //seconds

        out += (hours <= 9 ? '0' : '') + hours + " " + ((hours == 1) ? "hour" : "") + ": ";
        out += (mins <= 9 ? '0' : '') + mins + " " + ((mins == 1) ? "min" : "") + ": ";
        out += (secs <= 9 ? '0' : '') + secs + " " + ((secs == 1) ? "sec" : "") + ": ";
        out = out.substr(0, out.length - 2);
        document.getElementById(iid).innerHTML ="<b>"+ out +"</b>";

        setTimeout(function () { GetCountTimer(year, month, day, h, i, s, iid) }, 1000);
    }
}
